package inc.gome.dynamic.datasource.controller;



import inc.gome.dynamic.datasource.logread.LargeText;
import inc.gome.dynamic.datasource.logread.ReadLogFileUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;


/**
 * 文件读取Demo
 */
@Controller
public class LogReadDemo {


    /**
     *   参数中可携带 start  标识从什么位置开始读取
     * @param path  读取文件名称
     * @param completed  是否完整服务
     * @param req
     * @param res
     */
    @RequestMapping("/getlog")
    public void getLog(String path, boolean completed, HttpServletRequest req, HttpServletResponse res){
        System.out.println(path);
        //直接读出
        LargeText largeText = ReadLogFileUtils.newLargeText(path,completed);
        //捕捉异常信息
        try {
            largeText.doProgressText(req,res);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }




}
